package de.koller.transit.engine.paper;

import de.koller.aframe.plain.PlainQuality;
import de.koller.aframe.plain.Sprite;
import de.koller.aframe.util.misc.ABoundingBox;
import de.koller.transit.TNode;
import de.koller.transit.TransitStart;
import de.koller.transit.engine.brush.Brush;
import java.awt.BasicStroke;
import java.awt.Graphics2D;
import java.awt.Transparency;
import java.awt.geom.Line2D;

public class Paper extends TNode {
	
	private Sprite paperBuffer;

	@Override
	protected void init() {
		super.init();
		
		paperBuffer = new Sprite( troot.display.getGraphicsConfiguration().createCompatibleImage( 
				TransitStart.WIDTH, TransitStart.HEIGHT, Transparency.OPAQUE ) );
		paperBuffer.raster.clear( 0xff_ffffff );
	}
	
	public void updatePaint( Brush b ) {
		Graphics2D g = paperBuffer.graphics;
		//PlainQuality.best( g );
		g.setColor( b.color.getAWT() );
		g.setStroke( new BasicStroke( (int)b.size.getValue() * 2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND ) );
		g.draw( new Line2D.Double( b.position.getPrevious().x, b.position.getPrevious().y, 
				b.position.getCurrent().x, b.position.getCurrent().y ) );
		g.setStroke( new BasicStroke( 0 ) );
	}
	
	public void renderThis( Graphics2D g, ABoundingBox clip ) {
		g.drawImage( paperBuffer.image, (int)clip.x, (int)clip.y, (int)clip.x + (int)clip.w, (int)clip.y + (int)clip.h, 
				(int)clip.x, (int)clip.y, (int)clip.x + (int)clip.w, (int)clip.y + (int)clip.h, null);
	}
	
}
